/*
 * @lc app=leetcode.cn id=507 lang=cpp
 *
 * [507] 完美数
 */

// @lc code=start
class Solution
{
public:
  bool checkPerfectNumber(int num)
  {
    int sum = 1;
    for (int i = 2; i * i <= num; ++i) {
      if (num % i == 0) {
        sum += i;
        if (i != num / i)
          sum += num / i;
      }
    }
    return num != 1 && sum == num;
  }
};
// @lc code=end
